import sys
def prime(n):
  for i in range(2,int(n ** 0.5)+1):
      if n % i== 0:
          return False
  return True
  
def nprime(n):
  if prime(n):
      return n
  l=n
  u=n
  while True:
      l-=1
      u+=1
      if prime(l):
          return l
      if prime(u):
          return u
        
a=list(map(str,input().split()))
b=""
data=['zero', 'one', 'two', 'three', 'four', 'five', 'six','seven', 'eight', 'nine']
if a[0] not in data or a[1] not in data or a[2] not in data or len(a)!=3 or a[0]=='zero':
  print("Wrong input")
  sys.exit()
for i in range(3):
  if a[i]=="zero":
    b+="0"
  elif a[i]=="one":
    b+="1"
  elif a[i]=="two":
    b+="2"
  elif a[i]=="three":
    b+="3"
  elif a[i]=="four":
    b+="4"
  elif a[i]=="five":
    b+="5"
  elif a[i]=="six":
    b+="6"
  elif a[i]=="seven":
    b+="7"
  elif a[i]=="eight":
    b+="8"
  elif a[i]=="nine":
    b+="9"
print(nprime(int(b)))